/*
 * @Author: your name
 * @Date: 2022-03-30 09:45:31
<<<<<<< HEAD
<<<<<<< HEAD
 * @LastEditTime: 2022-03-31 13:35:49
=======
 * @LastEditTime: 2022-04-06 16:50:33
>>>>>>> 1bad8c98418a972bc00beb3c18f27571a4ed2898
=======
 * @LastEditTime: 2022-04-11 20:10:25
>>>>>>> 508cb43723b0ed082f83fe7208f48f9cca504284
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \四阶段项目\erp-management-system\src\views\work\Writing.jsx
 */
import React, { useEffect, useRef, useState, } from 'react';
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
import { Form, Input, Button, Radio, Upload, Row, Col, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import './work.css';
import ModalInfo from './Modal'
import axios from '../../../utils/myAxios'
// import E from 'wangeditor'
import ReactWEditor from 'wangeditor-for-react';

const Writing = () => {
    // const writeForm = useRef()
    const [writeForm] = Form.useForm()
    const navigate = useNavigate();
    const [inputVlaue, setinputVlaue] = useState('');
    const [getEditor, setgetEditor] = useState('')
    //富文本
    const editorRef = useRef(null)

    //选择人
    const getPerson = (v) => {
        // console.log('+++', v);
        setinputVlaue(v)
    }
    //表单提交函数
    const onFinish = (values) => {
        console.log('Success:', values);
    };

    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };

    //上传附件

    const initfileList = [
        {
            uid: '-1',
            name: 'xxx.png',
            status: 'done',
            url: 'http://www.baidu.com/xxx.png',
        },
    ]
    const [fileList, setfileList] = useState([initfileList])
    //文件发生改变
    // const fileChange = info => {
    //     let fileList = [...info.fileList];
    //     const { file } = info
    //     fileList = fileList.slice(-2);
    //     fileList = fileList.map(file => {
    //         if (file.response) {
    //             file.url = file.response.url;
    //         }
    //         return file;
    //     });
    //     setfileList(fileList);
    //     console.log('fileList', file.status, fileList);
    // };
   
    //调用接口
    // const uploadFileList = (file) => {
    //     console.log(file);
    //     const formData = new FormData()
    //     formData.append('file', file)
    //     console.log('all', formData.getAll('file'));
    //     axios.post('http://139.155.237.161:8080/annoEnclosure/insert', formData).then(res => {
    //         console.log(res);
    //     })
    // }
    const normFile = (e)=>{
        console.log('upload event',e.file);
        const formData = new FormData()
        formData.append('file',e.fileList)
        axios.post('/annoEnclosure/insert')
        .then(res=>{
            
        })
        // console.log(Array.isArray(e));
        // if(Array.isArray(e)){
        //     return e
        // }
        // return e && e.fileList
       
    }
     //上传文件之前
     const beforeUpload = (file) => {
        return false

    }
    //移除文件
    const fileRemove = () => {

    }


    //保存
    const onSubmt = () => {
        // navigate(-1)
        console.log('setFieldsValue', inputVlaue);
        const fieldsValue = writeForm.getFieldsValue()
        console.log(fieldsValue);/*  */
        const { classfiyGroup, content, upload } = fieldsValue
        //提交人
        const employeeName = '超级管理员'
        //分类/*  */
        const typeValue = ['工作心得', '日报', '周报', '月报', '季报', '年报']
        const getTypeValue = typeValue.filter((item, index) => {
            return index === classfiyGroup
        })[0]
        console.log('classfiyGroup', classfiyGroup);
        //标题
        const title = ` ${employeeName} ${getTypeValue}`
        //时间
        const time = Date()
        const getTime = moment(time).format('YYYY-MM-DD HH:mm:ss')
        console.log(getTime);
        //总数据
        const jsonData = {
            "contacts": inputVlaue,
            "content": content,
            "reporttime": getTime,
            "employeeName": employeeName,
            "title": title,
            "type": classfiyGroup,
            "employeeId": 12,
            "status": 0
        }
        console.log('=====', jsonData);
        axios.post('/anno/insert', {
            "contacts": inputVlaue,
            "content": content,
            "reporttime": getTime,
            "employeeName": employeeName,
            "title": title,
            "type": classfiyGroup,
            "employeeId": 12,
            "status": 0
        },
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .then(res => {
                console.log(res);
            })
            .catch(err => {
                console.log(err);
            })

    }
    //关闭
    const onClose = () => {
        navigate(-1)
    }


    return (
        <>
            <h3>提交工作报告</h3>
            <Form
                name="basic"
                labelCol={{ span: 8 }
                }
                wrapperCol={{ span: 16 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
                form={writeForm}
            >
                <Row>
                    <Col span={24}>
                        <Form.Item
                            label="接收人"
                            name='accecpetGroup'
                            labelCol={{ span: 3 }}
                        >
                            <>
                                <Input disabled style={{ marginRight: '10px', color: 'black' }} value={inputVlaue} />
                                <ModalInfo getPerson={getPerson} />
                            </>
                        </Form.Item>

                    </Col>
                </Row>
                <Row>
                    <Col span={24}>
                        <Form.Item
                            label="分类"
                            name="classfiyGroup"
                            labelCol={{ span: 3 }}
                        >
                            <Radio.Group>
                                <Radio value={0}>工作心得</Radio>
                                <Radio value={1}>日报</Radio>
                                <Radio value={3}>周报</Radio>
                                <Radio value={4}>月报</Radio>
                                <Radio value={5}>季报</Radio>
                                <Radio value={6}>年报</Radio>
                            </Radio.Group>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={24}>
                        <Form.Item
                            label="工作总结"
                            name='content'
                            labelCol={{ span: 3 }}
                        >
                            <ReactWEditor
                                initialValues={''}
                                ref={editorRef}
                            />
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={24}>
                        <Form.Item
                            label="附件"
                            name="upload"
                            labelCol={{ span: 3 }}
                            valuePropName='fileList'
                            getValueFromEvent={normFile}
                        >
                            <Upload
                                // action={'http://139.155.237.161:8080/annoEnclosure/insert'}
                                multiple
                                customRequest={() => false}
                                fileList={fileList}
                                onRemove={fileRemove}
                                // onChange={(file) => fileChange(file)}
                                beforeUpload={beforeUpload}
                            >
                                <Button type='primary'>选择文件</Button>
                            </Upload>
                        </Form.Item>
                    </Col>
                </Row>

                <Row justify='center' className='flow-writing'>
                    <Button icon={<PlusOutlined />} type="primary" onClick={onSubmt} className='writingBtnSave'>保存</Button>
                    <Button icon={<PlusOutlined />} type="primary" onClick={onClose} className='writingBtnClose'>关闭</Button>
                </Row>

            </Form >

        </ >
    );
}

export default Writing;
